Page({
  data: {
    favList: [
      {
        id: 1,
        shopName: '两句服饰旗舰店',
        img: '/pages/goodsDetail/1749115285878.png',
        title: 'NASA联名卡通小狗短袖T恤男女2025夏季新款宽松休闲',
        spec: 'M号',
        price: 59.9,
        num: 1,
        checked: false
      },
      {
        id: 2,
        shopName: 'ARISEISM',
        img: '/pages/goodsDetail/1749115306067.png',
        title: 'Ariseism 美式复古长袖T恤女春季新款宽松上衣',
        spec: 'M号',
        price: 105,
        num: 1,
        checked: false
      }
    ],
    totalPrice: '0.00'
  },
  onCheck(e) {
    const id = e.currentTarget.dataset.id;
    let favList = this.data.favList.map(item => {
      if (item.id == id) item.checked = !item.checked;
      return item;
    });
    this.setData({ favList }, this.calcTotal);
  },
  onNumInput(e) {
    const id = e.currentTarget.dataset.id;
    let value = parseInt(e.detail.value) || 1;
    let favList = this.data.favList.map(item => {
      if (item.id == id) item.num = value;
      return item;
    });
    this.setData({ favList }, this.calcTotal);
  },
  calcTotal() {
    let total = 0;
    this.data.favList.forEach(item => {
      if (item.checked) total += item.price * item.num;
    });
    this.setData({ totalPrice: total.toFixed(2) });
  },
  goOrderConfirm() {
    wx.navigateTo({ url: '/pages/orderConfirm/orderConfirm' });
  }
}); 